package com.neteast.androidclient.newscenter.domain;

import java.nio.ByteBuffer;
import java.util.Arrays;

import com.neteast.androidclient.newscenter.Global;

public class InfoReceiveResponse {
	byte cmd=Global.NET_NEW_INFO_RECEIVED; 
	/**通信协议 */
	public int protocolVersion;
	/**报文id*/
	public int msgId;
	/**保留字段长度*/
	public int reserveLen;
	/**保留数据*/
	public byte[] reserve;
	
	/**
	 * 
	 * @param protocolVersion int 通信协议
	 * @param msgId int 报文id
	 *
	 */
	public InfoReceiveResponse(int protocolVersion, int msgId) {
		super();
		this.protocolVersion = protocolVersion;
		this.msgId = msgId;
		this.reserveLen = 0;
	}
	/**
	 * @param protocolVersion int 通信协议
	 * @param msgId int 报文id
	 * @param reserveLen int 保留字段长度
	 * @param reserve byte[] 保留字段
	 */
	public InfoReceiveResponse(int protocolVersion, int msgId,int reserveLen, byte[] reserve) {
		super();
		this.protocolVersion = protocolVersion;
		this.msgId = msgId;
		this.reserveLen = reserveLen;
		this.reserve = reserve;
	}

	public byte[] getMessage(){
		ByteBuffer byteBuffer=ByteBuffer.allocate(13+reserveLen);
		byteBuffer.put(cmd);
		byteBuffer.putInt(protocolVersion);
		byteBuffer.putInt(msgId);
		byteBuffer.putInt(reserveLen);
		if (reserveLen>0) {
			byteBuffer.put(reserve);
		}
		byteBuffer.flip();
		return byteBuffer.array();
	}
	@Override
	public String toString() {
		if (reserve!=null) {
			return "InfoReceiveResponse [cmd=" + cmd + ", protocolVersion="
					+ protocolVersion + ", msgId=" + msgId + ", reserveLen="
					+ reserveLen + ", reserve=" + Arrays.toString(reserve) + "]";
		} else {
			return "InfoReceiveResponse [cmd=" + cmd + ", protocolVersion="
					+ protocolVersion + ", msgId=" + msgId + ", reserveLen="
					+ reserveLen +  "]";
		}
		
	}
	
}
